Regexp gl_reModParts = regexp("^([^-]+-[^-]+-)([0-9]+)$") // Declare constant Regexp in main context, // since 'regexp' is EXTREMELY inefficient and wasteful // Disect gl_reModParts: // [^-] any char except dash // [^-]+ One or more chars except dash // [^-]+- One or more chars except dash, then a dash // ([^-]+-[^-]+-) match 1, chars-dash-chars-dash // [0-9]+ One or more digits // ([0-9]+) match 2, one or more digits // ("^ at start of string // $") at end of string bool GetModParts(string NameMod, &BasePart, &NumberPart) { // Split the well formed module name into its parts, // Well Formed is: // o exactly two dashes // o characters before 1st dash // o characters between dashes // o only digits after 2nd dash // The BasePart include everything up to 2nd dash // The NumberPart includes the digits // e.g. Base-Part-22 has NumberPart "22" // If poorly formed, erase output strings and return false if (gl_reModParts NameMod) { BasePart = NameMod[match 1] NumberPart = NameMod[match 2] return(true) } else { BasePart = "" NumberPart = "" return(false) } } // end GetModParts() void Test_GetModParts(string NameMod) { string BasePart, NumberPart bool Result = GetModParts(NameMod, BasePart, NumberPart) print Result "\t[" BasePart "]\t#" NumberPart "\t*" NameMod "*\n" } Test_GetModParts("CTRS-DIA-118") Test_GetModParts("1-2-03") Test_GetModParts("CTRS-DIA-118x") // Bad, x at end Test_GetModParts("CTRSDIA-118") // Bad, only one dash Test_GetModParts("a-b-c-44") // Bad, 3 dashes Test_GetModParts("-b-33") // Bad, nothing before dash Test_GetModParts("a--33") // Bad, nothing between dashes Test_GetModParts("a-b-") // Bad, no numbers